#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "common.h"

int input_data();
int dijkstra(int **arr);


int main()
{
    time_t m_start,m_end;
	m_start = clock();    //!< Time units are ms
    FILE *fp1;
    if ((fp1 = fopen("test.txt","r")) == NULL)
	{
		printf("create test.txt \n");
		build_data();
		return 0;
	}
    fclose(fp1);
    input_data();
    m_end   = clock();
	printf("\n----------------main method run used %f ms------------\n",difftime(m_end,m_start));
    return 0;
}


int input_data(){
    int **Array;
    int x,i=0;
    int m=0,n=0;
    Array=(int **)malloc(RANKNUM*sizeof(int *));
    for(i=0;i<RANKNUM;i++){
        Array[i]=(int *)malloc(RANKNUM*sizeof(int));
    }
    FILE * fp_read;
    if ((fp_read = fopen("test.txt","r")) == NULL)
	{
		printf("can not open input file \n");
		return 0;
	}
    /*get data from edgeWeight.text to initialize dynamic array "Array"*/
    while(fscanf(fp_read,"%d%*[^0-9]",&x)>0){
        if(n<RANKNUM){
            Array[m][n++]=x;
        }else{
            n=0;
            Array[++m][n++]=x;
        }
    }
    /*dijkstra algorithm*/
    dijkstra(Array);

    fclose(fp_read);
    free(Array);
    return 0;
}


int dijkstra(int **arr){
    int i,j;
    /*print the Array*/
    for(i=0;i<RANKNUM;i++)
    {
        for(j=0;j<RANKNUM;j++)
        {
            printf("%d\t",*(*(arr+i)+j));
        }
        printf("\n");
    }

    printf("%d",arr[1][1]);
    return 0;
}
